<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <ul class="list">
        <li></li>
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');

      //   btns[0].onclick =function(){
      //     let p = axios.get('http://localhost:3000/movies');

      //     p.then(({data})=>{
      //        console.log(data);
      //     })
      //   }

        btns[0].onclick = async function(){
          let {data} = await axios.get('http://localhost:3000/movies');
          console.log(data);
        }

        btns[1].onclick =async function(){
           let {data} = await axios.post('http://localhost:3000/movies',{
               name:"西游记",
               director:"吴承恩",
               star:"孙悟空"
            })

            console.log(data);
        }
        
        btns[2].onclick =async function(){
           let res = await axios.put('http://localhost:3000/movies/9',{
              name:"三国演义"
           })

           console.log(res);
        }
    
        btns[3].onclick =async function(){
           let res = await axios.patch('http://localhost:3000/movies/8',{
              name:"水浒传"
           })

           console.log(res);
        }
    
        btns[4].onclick =async function(){
          let res = await axios.delete('http://localhost:3000/movies/9');

          console.log(res);
        }
    </script>
</body>

</html>